package com.lkd.lkdadmin.controller;


import com.lkd.lkdadmin.service.ISkuService;
import com.lkd.lkdadmin.constant.MessageConstant;
import com.lkd.lkdadmin.pojo.result.R;
import com.lkd.lkdadmin.utils.AliyunOSSOUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-02-10
 */
@RestController
@RequestMapping("/api/vm-service/sku")
@Api(tags = "商品管理")
@Slf4j
public class SkuController {

    @Autowired
    private AliyunOSSOUtil aliyunOSSOUtil;

    @Autowired
    private ISkuService iSkuService;

    /**
     * 商品图片上传
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/fileUpload")
    @ApiOperation("商品图片上传")
    public R uploadFile(MultipartFile file) throws Exception{
        log.info("文件上传:{}",file);
        try {
            String url = aliyunOSSOUtil.upload(file.getBytes(), file.getOriginalFilename());
            return R.ok(url);
        } catch (Exception e) {
            log.error("文件上传失败 {}",e);
        }
        return R.fail(MessageConstant.UPLOAD_FAILED);
    }

}
